﻿using System;
using System.Collections.Generic;

namespace Abs.Core.Models.Room
{
    public class RoomAvailability
    {
        public class Indexer
        {
            private RoomAvailability RoomAvailability { get; set; }

            internal Indexer(RoomAvailability roomAvailability)
            {
                this.RoomAvailability = roomAvailability;
            }//end of internal TimeIndexer(RoomAvailability roomAvailability)

            public bool this[int time]
            {
                get
                {
                    if(this.RoomAvailability.AvailabilityAtTime.ContainsKey(time))
                        return this.RoomAvailability.AvailabilityAtTime[time];
                    return false;
                }
                internal set
                {
                    this.RoomAvailability.AvailabilityAtTime[time] = value;
                }
            }//end of public bool this[int time]
        }//end of public class TimeIndexer

        private Indexer indexer;

        internal RoomAvailability()
        {
            this.AvailabilityAtTime = new Dictionary<int, bool>();
            this.indexer = new Indexer(this);
        }//end of internal RoomAvailability()

        public int RoomId { get; internal set; }
        public string RoomName { get; internal set; }
        public DateTime StartTime { get; internal set; }
        public DateTime EndTime { get; internal set; }
        //Use Indexer Property to access AvailabilityAtTime 
        private IDictionary<int, bool> AvailabilityAtTime { get; set; }
        public Indexer IsAvailableAtTime 
        { 
            get
            {
                return this.indexer;
            }
        }//end of public Indexer IsAvailableAtTime 


        internal void InitIsAvailableAtTime()
        {
            for(var min = this.StartTime.Hour; min < this.EndTime.Hour; min++)
            {
                this.AvailabilityAtTime.Add(min, true);
            }//end of for(var min = minTime; min < maxTime; min++)
        }//end of private void InitIsAvailableAtTime(int maxTime, int minTime)
    }//end of public class RoomAvailability
}//end of namespace ABS.Models.Room